package java虚拟机.chapter7.clazzloader;

/**
 * -XX:+TraceClassLoading
 *
 * @author juntao zhang
 */
public class SonFatherFactory {

  public static class Father {

    public final static int value2 = 10;

    static {
      System.out.println("this is father!");
      value = 11;
//      System.out.println(value);

    }

    public static int value = 10;
  }

  public static class Son extends Father {

    public static int value3 = 12;

    static {
      System.out.println("this is son!");
    }
  }

  public static void main(String[] args) {//(字节码指令)
    System.out.println(Son.value);      //(getstatic father)  loaded Father => loaded Son => run father static
//    System.out.println(Son.value3);     //(getstatic son)     loaded Father => loaded Son => run father static => run son static
//    System.out.println(Son.value2);     //(常量池)             loaded Father => loaded Son
//    Father[] fathers = new Father[10];  //(newarray)          loaded Father
//    Son[] sons = new Son[10];           //(newarray)          loaded Father => loaded Son
//    new Son();                          //(new)               loaded Father => loaded Son => run father static => run son static

  }

  private static void test() {
//    Father[] arr = new Son[2];
//    arr[1] = new Son();
//    List<Father> list = new ArrayList<Son>();
  }

}
